package com.itheima52.mobilesafe.activity;

import com.itheima52.mobilesafe.R;
import com.itheima52.mobilesafe.utils.SmsUtils;
import com.itheima52.mobilesafe.utils.SmsUtils.BackUpSms;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.os.Looper;
import android.view.View;
import android.widget.Toast;

/**
 * 高级工具
 * 
 * @author ludaxu
 * 
 */
public class AToolsActivity extends Activity {

	private ProgressDialog dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_atools);

	}

	/**
	 * 电话号码查询
	 * 
	 * @param view
	 */
	public void numberAddressQuery(View view) {
		startActivity(new Intent(AToolsActivity.this, AddressActivity.class));
	}

	/**
	 * 短信备份
	 * 
	 * @param view
	 */
	public void backUpsms(View view) {
		

		dialog = new ProgressDialog(AToolsActivity.this);
		dialog.setTitle("提示");
		dialog.setMessage("稍安勿躁,正在备份,等待...");
		dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
		dialog.show();

		new Thread() {
			@Override
			public void run() {
				// TODO Auto-generated method stub
				super.run();
				boolean result = SmsUtils.backUp(AToolsActivity.this, new BackUpSms() {
					
					@Override
					public void onBackUpSms(int process) {
						dialog.setProgress(process);
					}
					
					@Override
					public void befor(int count) {
						dialog.setMax(count);
					}
				});
				dialog.dismiss();
				if (result) {
					Looper.prepare();
					Toast.makeText(AToolsActivity.this, "短信备份成功", 0).show();
					Looper.loop();

				} else {
					Looper.prepare();
					Toast.makeText(AToolsActivity.this, "短信备份失败", 0).show();
					Looper.loop();
				}
				
			}

		}.start();

	}

}
